/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.application.ejb.reviewtemplate.impl;

import com.nus.application.ejb.reviewtemplate.ReviewTemplateEjbLocal;
import com.nus.dataaccess.dao.reviewtemplate.ReviewTemplate;
import com.nus.dataaccess.dao.reviewtemplate.dao.ReviewTemplateDao;
import com.nus.dataaccess.dao.util.HibernateUtil;
import java.util.List;
import java.util.Map;
import javax.annotation.security.PermitAll;
import javax.ejb.Stateless;

/**
 *
 * @author robin.foe
 */
@Stateless
@PermitAll
public class ReviewTemplateEjb implements ReviewTemplateEjbLocal{

    @Override
    public ReviewTemplate getById(Long id) {
        return ReviewTemplateDao.getInstance().get(id);
    }

    @Override
    public void persist(ReviewTemplate reviewTemplate) {
         try {
            HibernateUtil.beginTransaction();
            ReviewTemplateDao.getInstance().save(reviewTemplate);
            HibernateUtil.commitTransaction();
        } catch (Exception e) {
            HibernateUtil.rollbackTransaction();
        }
    }

    @Override
    public List<ReviewTemplate> paginate(int first, int pageSize, String sortField, boolean ascending, Map<String, String> filters) {
        return ReviewTemplateDao.getInstance().paginate(first, pageSize, sortField, ascending, filters);
    }

    @Override
    public int countTotal(Map<String, String> filters) {
        try{
               return ReviewTemplateDao.getInstance().getTotalCount(filters);
        }catch(Exception e){
            e.printStackTrace();
        }
        return ReviewTemplateDao.getInstance().getTotalCount(filters);
    }
    
    
    public String test(String test){
    return "EJB " + test;
            
            }
    
}
